perm filename A111.TEX[106,PHY] blob
sn#807818 filedate 1985-11-15 generic text, type C, neo UTF8
COMMENT ā VALID 00002 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 \magnification\magstephalf
C00005 ENDMK
Cā;
\magnification\magstephalf
\input macro.tex
\def\today{\ifcase\month\or
January\or February\or March\or April\or May\or June\or
July\or August\or September\or October\or November\or December\fi
\space\number\day, \number\year}
\baselineskip 14pt
\rm
\font\rmn=amr9
\line{\sevenrm a111.tex[106,phy] \today\hfill}
\medskip
\line{{\bf Example} [While]\hfil}
I want to save my money to buy a sailboat, and sail away to Tahiti. I have
a modest initial bank balance (call it {\tt FIRSTBAL}). At the beginning of each
year I~deposit a fixed amount ({\tt DEPOSIT}); at the end of the year, the bank
pays me interest, multiplying my deposit by $1+{\tt RATE}$. The boat costs
{\tt BOATPRICE}. A~program to determine how many years are required is:
{\obeylines\obeyspaces\let =\ \tt
READ(FIRSTBAL,DEPOSIT,RATE,BOATPRICE);
BALANCE:=FIRSTBAL;
COUNT:=0
WHILE BALANCE<BOATPRICE DO
BEGIN
BALANCE:=BALANCE+DEPOSIT;
BALANCE:=BALANCE*(1+RATE);
COUNT:=COUNT+1 (* ONE YEAR HAS PASSED *)
END;
WRITE ('YOU MUST WORK', COUNT, 'YEARS FOR YOUR BOAT')
END.
}
Again, the program above works correctly even when the answer is zero;
because it tests before executing the body of the iteration, it is able
to skip the body entirely.
(Note to instructor: if your students insist on using {\tt REPEAT}, show them
why it fails here when the answer is zero.)
\bigskip
\line{\copyright 1985 Robert W. Floyd;
First draft (not published) March 15, 1985\hfil}
%revised: Date; subsequently revised.\hfill}
\bye